﻿using System;
using Cosmos.Compiler.Builder;
using Cosmos.Hardware;

namespace _3DOS
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion

        // Main entry point of the kernel
        public static void Init()
        {
            // version v0.0.4.5

            #region COSMOS BOOT (Boots basic cosmos code)
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
            #endregion
            VGAScreen.SetPaletteEntry(0, 0x00, 0x00, 0x00); //Black          
            VGAScreen.SetPaletteEntry(1, 0xFF, 0xFF, 0xFF); //White  
            VGAScreen.SetPaletteEntry(4, 0x00, 0x3C, 0x00);//Green .0  
            VGAScreen.SetPaletteEntry(5, 0x00, 0xCC, 0x00);//Green .3
            VGAScreen.SetPaletteEntry(11, 0x00, 0x99, 0xFF); //Blue
            VGAScreen.SetPaletteEntry(7, 0x00, 0x75, 0x00);//Green .6
            VGAScreen.SetPaletteEntry(2, 0x3C, 0x00, 0x00);//Red 
            VGAScreen.SetPaletteEntry(8, 0x00, 0x99, 0x00);//Green .9
            VGAScreen.SetPaletteEntry(6, 0x66, 0xFF, 0x66);//Clock Back Green
            string promptcommand;
            VGAScreen.Clear(1);
            VGAScreen.SetTextMode(VGAScreen.TextSize.Size80x25);
            Console.Clear();
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            RestartConsole:
            Console.WriteLine("3DOS v 0.5.5 - dev console for the 3DOS library. (C) 3DOS Project 2011 - 12");
            while (true)
            {
                Console.Write("3DOS>");
                promptcommand = Console.ReadLine();
                if (promptcommand == @"OS.Shutdown" || promptcommand == @"OS /Shutdown" || promptcommand == @"OS --shutdown")
                {
                    Cosmos.Sys.Deboot.ShutDown();
                }
                if (promptcommand == @"OS" || promptcommand == @"OS." || promptcommand == @"OS /?" || promptcommand == @"OS --?" || promptcommand == @"OS.Help")
                {
                    Console.WriteLine("The following commands are allowed: OS.Shutdown - Shuts the computer down.");
                }
                if (promptcommand == @"Draw" || promptcommand == @"Draw." || promptcommand == @"Draw /?" || promptcommand == @"Draw --?" || promptcommand == @"Draw.Help")
                {
                    Console.WriteLine("The following commands are allowed: Draw.ISOGrid");
                }
                if (promptcommand == @"Draw.ISOGrid")
                {
                    VGAScreen.SetMode320x200x8();
                    VGAScreen.Clear(0);
                    ISOGrid.draw(0, 0);
                    ISOGrid.draw(0, 16);
                    ISOGrid.draw(12, 6);
                    ISOGrid.draw(12, 22);
                    ISOGrid.draw(24, 12);
                    ISOGrid.draw(24, 28);
                    ISOGrid.draw(36, 18);
                    ISOGrid.draw(36, 34);
                    int i = 0;
                    while (i == 0)
                    {
                        if (Keyboard.CtrlPressed == true)
                        {
                            VGAScreen.Clear(1);
                            VGAScreen.SetTextMode(VGAScreen.TextSize.Size80x25);
                            Console.Clear();
                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                            Console.WriteLine("+ Draw.ISOGrid executed sucessfully");
                            Console.WriteLine();
                            Console.BackgroundColor = ConsoleColor.White;
                            Console.ForegroundColor = ConsoleColor.Black;
                            i = 1;
                            goto RestartConsole;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Command unrecognised or syntax incorrect, try looking ");
                    Console.WriteLine("the command up in our wiki. Command are CAPS sensitive");
                    Console.WriteLine();
                }
            }

        }
        public static void DrawText(uint[] Arr, int width, int length, uint tcolor, uint x, uint y)
        {
            uint i;
            uint t;
            int count = 0;

            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        VGAScreen.SetPixel320x200x8(x + t, y + i, tcolor);

                    }

                }
            }
        }
    }
}